package com.eric.text;

import java.util.List;
import java.util.Map;

import org.fnlp.app.keyword.AbstractExtractor;
import org.fnlp.app.keyword.WordExtract;
import org.fnlp.nlp.cn.CNFactory;
import org.fnlp.nlp.cn.tag.CWSTagger;
import org.fnlp.nlp.corpus.StopWords;
import org.fnlp.util.exception.LoadModelException;
import org.jsoup.nodes.Document;

import com.eric.Config;

public class FNLPAbstractWorker extends AbstractTextWorker {

	AbstractExtractor key;

	CNFactory f;

	public FNLPAbstractWorker(Object input) {
		super(input);
	}

	@Override
	public void initThis() {
		docPart(Config.DOC_PART.ARTICLE);
		StopWords sw = new StopWords(Config.STOP_WORDS);

		CWSTagger seg = null;
		try {
			f = CNFactory.getInstance("models");
			seg = CNFactory.seg;

			if (customWords.size() > 0)
				CNFactory.addDict(customWords);
		} catch (LoadModelException e) {
			e.printStackTrace();
		}
		key = new WordExtract(seg, sw);
	}

	@Override
	public void produce() {
		init();
		initThis();
		getAbstractKW();
	}

	public void getAbstractKW() {
		Map<String, Integer> ans = key.extract(text, topN);

		for (Map.Entry<String, Integer> entry : ans.entrySet()) {
			String keymap = entry.getKey().toString();
			String value = entry.getValue().toString();
			result.add(keymap + "=" + value);
			System.out.println(keymap + "=" + value);
		}
	}

	@Override
	public List<String> getContext() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<String> produce(String text, Document doc) {
		// TODO Auto-generated method stub
		return null;
	}
}
